package com.chianghao.nio.core.handle.http;


import java.io.ByteArrayOutputStream;
import java.nio.charset.Charset;

/**
 * @author ChiangHao
 */
public class HttpResponse {


    private ByteArrayOutputStream output = new ByteArrayOutputStream();


    private int httpStatus;

    public ByteArrayOutputStream getOutput() {
        return output;
    }

    public void setOutput(ByteArrayOutputStream output) {
        this.output = output;
    }

    public int getHttpStatus() {
        return httpStatus;
    }

    public void setHttpStatus(int httpStatus) {
        this.httpStatus = httpStatus;
    }




    /**
     * 返回http 协议内容
     * @return
     */
    public String getHttpContent() {
        StringBuilder content = new StringBuilder();
        content.append("HTTP/1.1 200 OK").append((char)0x0d).append((char)0x0a);
        content.append("Connection: Keep-Alive").append((char)0x0d).append((char)0x0a);
        content.append("Content-Type: application/json; charset=utf-8").append((char)0x0d).append((char)0x0a);
        content.append((char)0x0d).append((char)0x0a);
        String body = new String(this.output.toByteArray(), Charset.forName("UTF-8"));
        content.append(body).append((char)0x0d).append((char)0x0a);
        return content.toString();
    }
}
